class ElementWise:
    def input_shape_correct(self, shapes):
        if len(shapes) != 2:
            return False

        if len(shapes[0]) == 1 and len(shapes[1]) > 1:
            shapes[0][0] = shapes[1][-1]
            return True

        if len(shapes[1]) == 1 and len(shapes[0]) > 1:
            shapes[1][0] = shapes[0][-1]
            return True    

        #shapes[1] = shapes[0]
        max_shape = shapes[0]
        if len(shapes[1]) > len(shapes[0]):
            max_shape = shapes[1]

        min_shape = shapes[1]
        if len(shapes[0]) < len(shapes[1]):
            min_shape = shapes[0]

        for i in range(len(min_shape)):
            if max_shape[-1-i] != min_shape[-1-i] and min_shape[-1-i] != 1:
                  max_shape[-1-i] = 1  

    def infer_output_shape(self, shapes):
        if len(shapes) != 2:
            return shape, False

        max_shape = shapes[0]
        if len(shapes[1]) > len(shapes[0]):
            max_shape = shapes[1]

        min_shape = shapes[1]
        if len(shapes[0]) < len(shapes[1]):
            min_shape = shapes[0]

        for i in range(len(min_shape)):
            if max_shape[-1-i] < min_shape[-1-i]:
                  max_shape[-1-i] = min_shape[-1-i]  

        return max_shape, True
    